﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcControlsToolkit
{
    public class BaseObject
    {
        protected Dictionary<string, string> Attributes = new Dictionary<string, string>();

        protected string GetString(string key)
        {
            if (!Attributes.ContainsKey(key)) return null;
            string temp = Attributes[key];
            return temp.Substring(1, temp.Length - 2);
        }

        protected void SetString(string key, string value)
        {
            if (string.IsNullOrEmpty(value))
                Attributes[key] = null;
            else
                Attributes[key] = "\"" + value + "\"";
        }

        public override string ToString()
        {
            var result = new StringBuilder();

            foreach (var key in Attributes.Keys)
            {
                result.AppendFormat(", {0}: {1}", key, Attributes[key]);
            }
            if (result.Length > 0)
                result.Remove(0, 1);

            result.Insert(0, "{");
            result.Append("}");

            return result.ToString();
        }
    }
}
